﻿@model DataAccess.DB.SanPham

@{
    ViewBag.Title = "Sản phẩm";
}

<div class="panel panel-default">
    <div class="panel-heading">
        Thay đổi thông tin Sản phẩm
    </div>
    <!-- /.panel-heading -->
    <div class="panel-body">
        <div class="row">
            <div class="col-lg-6">
                @using (Html.BeginForm())
                {
                    @Html.ValidationSummary(true)
                    <div class="form-group">
                        <label>Mã sản phẩm</label>
                        @Html.HiddenFor(model => model.ID)
                        @Html.TextBoxFor(model => model.MaSP, null, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.MaSP)
                    </div>
                    <div class="form-group">
                        <label>Tên sản phẩm</label>
                        @Html.TextBoxFor(model => model.TenSP, null, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.TenSP)
                    </div>
                    <div class="form-group">
                        <label>Hạn sử dụng</label>
                        @Html.TextBoxFor(model => model.HSD, "{0:dd/MM/yyyy}", new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.HSD)
                    </div>
                    <div class="form-group">
                        <label>Giá nhập mặc định</label>
                        @Html.TextBoxFor(model => model.GiaNhap, null, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.GiaNhap)
                    </div>
                    <div class="form-group">
                        <label>Giá bán mặc định</label>
                        @Html.TextBoxFor(model => model.GiaBan, null, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.GiaBan)
                    </div>
                    <div class="form-group">
                        <label>Đơn vị tính</label>
                        @Html.TextBoxFor(model => model.DonVi, null, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.DonVi)
                    </div>
                    <div class="form-group">
                        <label>Mô tả chi tiết</label>
                        @Html.TextAreaFor(model => model.Description, 6, 100, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.Description)
                    </div>

                    <input type="submit" value="Cập nhật" class="btn btn-default" />
                    @Html.ActionLink("Thoát", "Index", null, new { @class = "btn btn-default" })
                }
            </div>
        </div>
    </div>
    <!-- /.panel-body -->
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script src="~/Content/themeadmin/DatePicker/dist/js/bootstrap-datepicker.js" type="text/javascript"></script>
    <script src="~/Content/themeadmin/DatePicker/dist/locales/bootstrap-datepicker.vi.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="~/Content/themeadmin/DatePicker/dist/css/bootstrap-datepicker3.min.css" type="text/css" />
    <script type="text/javascript">
        $("#GiaBan").change(function () {
            $(this).formatCurrency();
            var num = '0';
            num = $this.val().replace(/,/g, '').replace('.', '');
            if (num === '' || isNaN(num)) {
                $this.val('0.00');
            }
        });
        $("#GiaNhap").change(function () {
            $(this).formatCurrency();
            var num = '0';
            num = $this.val().replace(/,/g, '').replace('.', '');
            if (num === '' || isNaN(num)) {
                $this.val('0.00');
            }
        });
        $('#HSD').datepicker({
            language: "vi",
        });
        $(function () {
            $.validator.addMethod(
            "date",
            function (value, element) {
                var s = value;
                s = value.replace(/\./g, '/');

                // Chrome requires tolocaledatestring conversion, otherwise just use the slashed format
                var d = new Date();
                return this.optional(element) || !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value))) || !/Invalid|NaN/.test(new Date(s));
            },
            ""
            );
        });
        $.validator.unobtrusive.parse();
    </script>
}